package com.seed.uaa.tenant.web;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import com.seed.uaa.web.organization.Organization;
import com.seed.uaa.web.role.Role;
import com.seed.core.enumeration.YesNo;
import com.seed.core.annotation.BelongsTo;
import com.seed.core.annotation.Habtm;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.List;

@Schema(description = "租户")
@Table(value = "uaa_tenant")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Tenant {
    @Id
    @Schema(title = "ID")
    private String id;

    @Schema(title = "所属部门", description = "租户所在的职能管理部门，也是组织")
    private String organizationId;

    @Schema(title = "名称")
    private String name;

    @Schema(title = "备注")
    private String remark;

    @Schema(title = "LOGO")
    private String logo;

    @Schema(title = "数据库地址")
    private String dbUrl;

    @Schema(title = "数据库用户名")
    private String dbUsername;

    @Schema(title = "数据库密码")
    private String dbPassword;

    @Schema(title = "租户名")
    private String tenantname;

    @Schema(title = "密码")
    private String password;

    @Schema(title = "盐")
    private String salt;

    @Schema(title = "截止日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDateTime expireDate;

    @Schema(title = "是否可用", description = "如果为no,则连下级用户也不能登录，用于主动停止使用系统")
    private YesNo usable;

    @Schema(title = "是否可登录", description = "如果为no,则连下级用户也不能登录，用于被动停止使用系统")
    private YesNo loginable;

    @Schema(title = "是否启用", description = "如果为no,则自己不能登录，不影响下级")
    private YesNo enable;

    @Schema(title = "是否激活", description = "未激活的账号需要先走激活流程")
    private YesNo active;

    @Schema(title = "原因", description = "账号不能登录系统的原因")
    private String reason;

    @Schema(title = "访问权限")
    private String actions;

    @Schema(title = "数据权限")
    private String datas;

    @Schema(title = "字段权限")
    private String fields;

    @Schema(title = "所属租户")
    private String tenantId;

    @Schema(title = "创建时间")
    @Column(onInsertValue = "now()")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdAt;

    @Schema(title = "创建时间")
    @Column(onInsertValue = "now()", onUpdateValue = "now()")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updatedAt;

    @Schema(title = "删除时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime deletedAt;

    @Schema(title = "版本号")
    @Column(version = true)
    private Long version;

    @Schema(title = "所属部门")
    @Column(version = true)
    @BelongsTo(selfColumn = "organizationId", targetColumn = "id", comment = "租户所属的管理部门")
    private Organization organization;

    @Schema(title = "角色")
    @Column(ignore = true)
    @Habtm(through = TenantRole.class, comment = "租户拥有的角色")
    private List<Role> roles;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getOrganizationId() {
        return organizationId;
    }

    public void setOrganizationId(String organizationId) {
        this.organizationId = organizationId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public String getDbUrl() {
        return dbUrl;
    }

    public void setDbUrl(String dbUrl) {
        this.dbUrl = dbUrl;
    }

    public String getDbUsername() {
        return dbUsername;
    }

    public void setDbUsername(String dbUsername) {
        this.dbUsername = dbUsername;
    }

    public String getDbPassword() {
        return dbPassword;
    }

    public void setDbPassword(String dbPassword) {
        this.dbPassword = dbPassword;
    }

    public String getTenantname() {
        return tenantname;
    }

    public void setTenantname(String tenantname) {
        this.tenantname = tenantname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public LocalDateTime getExpireDate() {
        return expireDate;
    }

    public void setExpireDate(LocalDateTime expireDate) {
        this.expireDate = expireDate;
    }

    public YesNo getUsable() {
        return usable;
    }

    public void setUsable(YesNo usable) {
        this.usable = usable;
    }

    public YesNo getLoginable() {
        return loginable;
    }

    public void setLoginable(YesNo loginable) {
        this.loginable = loginable;
    }

    public YesNo getEnable() {
        return enable;
    }

    public void setEnable(YesNo enable) {
        this.enable = enable;
    }

    public YesNo getActive() {
        return active;
    }

    public void setActive(YesNo active) {
        this.active = active;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getActions() {
        return actions;
    }

    public void setActions(String actions) {
        this.actions = actions;
    }

    public String getDatas() {
        return datas;
    }

    public void setDatas(String datas) {
        this.datas = datas;
    }

    public String getFields() {
        return fields;
    }

    public void setFields(String fields) {
        this.fields = fields;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    public LocalDateTime getDeletedAt() {
        return deletedAt;
    }

    public void setDeletedAt(LocalDateTime deletedAt) {
        this.deletedAt = deletedAt;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }
}
